#******************************************************************
#
# Copyright 2015 Samsung Electronics All Rights Reserved.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Import('env')
import os
import os.path
provisiontests_env = env.Clone()

src_dir = provisiontests_env.get('SRC_DIR')
######################################################################
# Build flags
######################################################################
provisiontests_env.PrependUnique(CPPPATH = [
		'../../include',
		'../../oc_logger/include',
		'../../csdk/stack/include',
		'../../csdk/security/include',
		'../../csdk/security/provisioning/include',
		'../../csdk/security/provisioning/include/oxm',
		'../../csdk/security/provisioning/include/internal',
		'../../csdk/stack/include/internal',
		'../../csdk/connectivity/api',
		'../../csdk/connectivity/external/inc',
		'../../csdk/ocsocket/include',
		'../../csdk/ocrandom/include',
		'../../csdk/logger/include',
		'../../../extlibs/gtest/gtest-1.7.0/include',
		'../../../extlibs/hippomocks-master/HippoMocks',
		'../../../extlibs/hippomocks-master/HippoMocksTest'
		])

provisiontests_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall', '-pthread'])
provisiontests_env.AppendUnique(LIBS = ['-lpthread', '-ldl'])
provisiontests_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
provisiontests_env.AppendUnique(LIBPATH = [src_dir + '/extlibs/gtest/gtest-1.7.0/lib/.libs'])
provisiontests_env.PrependUnique(LIBS = [
        'ocprovision',
		'oc',
		'ocpmapi',
		'octbstack',
		'oc_logger',
		'connectivity_abstraction',
		'coap',
		'gtest',
		'gtest_main',
		])

if env.get('SECURED') == '1':
    provisiontests_env.AppendUnique(LIBS = ['tinydtls'])
if env.get('DTLS_WITH_X509') == '1':
	provisiontests_env.AppendUnique(LIBS = ['CKManager'])
	provisiontests_env.AppendUnique(LIBS = ['asn1'])


if env.get('LOGGING'):
	provisiontests_env.AppendUnique(CPPDEFINES = ['TB_LOG'])

######################################################################
# Source files and Targets
######################################################################
unittests = provisiontests_env.Program('provisiontests', ['OCProvisioningTest.cpp'])

Alias("provisiontests", [unittests])

env.AppendTarget('provisiontests')
if env.get('TEST') == '1':
	target_os = env.get('TARGET_OS')
	if target_os == 'linux':
		out_dir = env.get('BUILD_DIR')
		result_dir = env.get('BUILD_DIR') + '/test_out/'
		if not os.path.isdir(result_dir):
			os.makedirs(result_dir)
		provisiontests_env.AppendENVPath('GTEST_OUTPUT', ['xml:'+ result_dir])
		provisiontests_env.AppendENVPath('LD_LIBRARY_PATH', [out_dir])
		provisiontests_env.AppendENVPath('LD_LIBRARY_PATH', ['./extlibs/gtest/gtest-1.7.0/lib/.libs'])
		ut = provisiontests_env.Command ('ut', None, out_dir + 'resource/provisioning/unittests/provisiontests')
		AlwaysBuild ('ut')

src_dir = provisiontests_env.get('SRC_DIR')
svr_db_src_dir = src_dir + '/resource/provisioning/examples/'
svr_db_build_dir = env.get('BUILD_DIR') +'/resource/provisioning/unittests/'
provisiontests_env.Alias("install", provisiontests_env.Install( svr_db_build_dir,
                                svr_db_src_dir + 'oic_svr_db_client.json'))
